/*
 * PanelSpace.java    J2RS - Jordi Sanchez
 *
 * Created on 8-dic-2011, 12:57:35
 */
package edu.uoc.tdp.client;

import edu.uoc.tdp.server.impl.SubsystemMaintenanceImpl;
import edu.uoc.tdp.i18n.TDPLanguageUtils;
import edu.uoc.tdp.i18n.TDPLanguageConstants;
import edu.uoc.tdp.dal.ManagementSpaces;
import edu.uoc.tdp.entity.Space;
import edu.uoc.tdp.entity.Resource;
import edu.uoc.tdp.customException.EIssueException;
import java.awt.Color;
import java.rmi.RemoteException;
import java.util.List;
import java.util.MissingResourceException;
import javax.swing.JComboBox;
import javax.swing.JOptionPane;
import java.util.logging.Logger;
import java.util.logging.Level;
import javax.swing.JFrame;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.table.AbstractTableModel;
import java.util.Calendar;
import java.util.Date;
import java.util.Arrays;
import java.util.*;
import java.text.*;

/**
 *
 * @author Jordi
 */
public class PanelSpace extends javax.swing.JFrame {

    private final String url = new String("rmi://localhost/eEspais");
    //private ManagementSpaces remoto;
    private Boolean NewSpace = false;
    public Space EspacioTrabajo = null;
    public String UsuarioActivo = null;

    /** Creates new form PanelSpace */
    public PanelSpace() throws RemoteException, edu.uoc.tdp.common.EIssueException {

        initComponents();


//        public static String  = "Client.Users.lblSpaceId";
//        public static String  = "Client.Spaces.lblDescription";
//        public static String  = "Client.Spaces.lblCapacity";
//        public static String  = "Client.Spaces.lblPriceHour";
//        public static String  = "Client.Spaces.lblPriceDay";
//        public static String  = "Client.Spaces.lblCity";
//        public static String  = "Client.Spaces.lblPostalCode";
//        public static String  = "Client.Spaces.lblHowToGet";
//        public static String  = "Client.Spaces.lblUtrlMap";

        lblFind1.setText(TDPLanguageUtils.getMessage(TDPLanguageConstants.CLIENT_PANELUSER_LBLFIND1));
        lblFindValue.setText(TDPLanguageUtils.getMessage(TDPLanguageConstants.CLIENT_PANELUSER_LBLFINDVALUE));
        lblIncactive.setText(TDPLanguageUtils.getMessage(TDPLanguageConstants.CLIENT_PANELUSER_LBLINACTIVE));

        lblSpaceId.setText(TDPLanguageUtils.getMessage(TDPLanguageConstants.CLIENT_PANELSPACE_LBLSPACEID));
        lblSpaceDesc.setText(TDPLanguageUtils.getMessage(TDPLanguageConstants.CLIENT_PANELSPACE_LBLDESCRIPTION));
        lblCapacity.setText(TDPLanguageUtils.getMessage(TDPLanguageConstants.CLIENT_PANELSPACE_LBLCAPACITY));
        lblPriceHour.setText(TDPLanguageUtils.getMessage(TDPLanguageConstants.CLIENT_PANELSPACE_LBLPRICEHOUR));
        lblPriceDay.setText(TDPLanguageUtils.getMessage(TDPLanguageConstants.CLIENT_PANELSPACE_LBLPRICEDAY));
        lblCity.setText(TDPLanguageUtils.getMessage(TDPLanguageConstants.CLIENT_PANELSPACE_LBLCITY));
        lblPostalCode.setText(TDPLanguageUtils.getMessage(TDPLanguageConstants.CLIENT_PANELSPACE_LBLPOSTALCODE));
        lblHowToGet.setText(TDPLanguageUtils.getMessage(TDPLanguageConstants.CLIENT_PANELSPACE_LBLHOWTOGET));
        lblUtrlMap.setText(TDPLanguageUtils.getMessage(TDPLanguageConstants.CLIENT_PANELSPACE_LBLURLMAP));

        btnFind.setText(TDPLanguageUtils.getMessage(TDPLanguageConstants.CLIENT_PANELUSER_BTNFIND));
        btnNew.setText(TDPLanguageUtils.getMessage(TDPLanguageConstants.CLIENT_PANELUSER_BTNNEW));
        btnModif.setText(TDPLanguageUtils.getMessage(TDPLanguageConstants.CLIENT_PANELUSER_BTNMODIF));
        btnDelete.setText(TDPLanguageUtils.getMessage(TDPLanguageConstants.CLIENT_PANELUSER_BTNDELETE));
        btnSave.setText(TDPLanguageUtils.getMessage(TDPLanguageConstants.CLIENT_PANELUSER_BTNSAVE));
        btnCancel.setText(TDPLanguageUtils.getMessage(TDPLanguageConstants.CLIENT_PANELUSER_BTNCANCEL));

        //Deshabilitem els texts
        EnableObjects(false);
        ObjectsStartStatus();

        //Omplim Grid Spaces
        try {
            cargarGrid();
        } catch (edu.uoc.tdp.common.EIssueException ex) { //FIXME
            Logger.getLogger(PanelSpace.class.getName()).log(Level.SEVERE, null, ex);
        }

        //Usuari actiu
        try {
            UsuarioActivo = Client.availableUser.getName();
            if (UsuarioActivo == "" || UsuarioActivo == null) {
                UsuarioActivo = "UNKNOWN";
            }
        } catch (Exception e) {
            Logger.getLogger(PanelUser.class.getName()).log(Level.SEVERE, null, e);
            UsuarioActivo = "UNKNOWN";
        } finally {
            lblUser.setText(UsuarioActivo);
        }

        // Omplim dades combo Usuaris        
        List<Resource> listaResources;
        listaResources = Client.remoteMaintenance.GetAllResources();
        cargarComboResources(cbResources, listaResources);

    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        lblFind1 = new javax.swing.JLabel();
        cbFind1 = new javax.swing.JComboBox();
        lblFindValue = new javax.swing.JLabel();
        btnFind = new javax.swing.JButton();
        jScrollPane2 = new javax.swing.JScrollPane();
        tblSpaces = new javax.swing.JTable();
        txtSpaceId = new javax.swing.JTextField();
        lblSpaceId = new javax.swing.JLabel();
        lblSpaceDesc = new javax.swing.JLabel();
        txtDescription = new javax.swing.JTextField();
        lblCapacity = new javax.swing.JLabel();
        txtCapacity = new javax.swing.JTextField();
        lblPriceHour = new javax.swing.JLabel();
        txtPriceH = new javax.swing.JTextField();
        lblPriceDay = new javax.swing.JLabel();
        txtPriceD = new javax.swing.JTextField();
        txtFindValue = new javax.swing.JTextField();
        lblUtrlMap = new javax.swing.JLabel();
        txtUrlMap = new javax.swing.JTextField();
        lblHowToGet = new javax.swing.JLabel();
        txtHowToGet = new javax.swing.JTextField();
        lblPostalCode = new javax.swing.JLabel();
        txtZipCode = new javax.swing.JTextField();
        lblCity = new javax.swing.JLabel();
        txtCity = new javax.swing.JTextField();
        lblSpaceDesc5 = new javax.swing.JLabel();
        txtAddress = new javax.swing.JTextField();
        lblIncactive = new javax.swing.JLabel();
        txtInactivUs = new javax.swing.JTextField();
        txtInactivDate = new javax.swing.JTextField();
        lblUser = new javax.swing.JLabel();
        btnNew = new javax.swing.JButton();
        btnModif = new javax.swing.JButton();
        btnSave = new javax.swing.JButton();
        btnDelete = new javax.swing.JButton();
        btnCancel = new javax.swing.JButton();
        btnBack = new javax.swing.JButton();
        jPanel2 = new javax.swing.JPanel();
        jScrollPane1 = new javax.swing.JScrollPane();
        tblSpaceResources = new javax.swing.JTable();
        lblSpaceDesc6 = new javax.swing.JLabel();
        cbResources = new javax.swing.JComboBox();
        btnAddRes = new javax.swing.JButton();
        btnDelRes = new javax.swing.JButton();
        btnDelAllRes = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setResizable(false);

        jPanel1.setBackground(new java.awt.Color(255, 255, 255));

        lblFind1.setText("Find Field");

        cbFind1.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Desription", "PostalCode" }));

        lblFindValue.setText("Value");

        btnFind.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icons/find.png"))); // NOI18N
        btnFind.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnFindActionPerformed(evt);
            }
        });

        tblSpaces.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null, null, null},
                {null, null, null, null, null, null},
                {null, null, null, null, null, null},
                {null, null, null, null, null, null}
            },
            new String [] {
                "UserId", "Name", "Surname1", "Surname2", "Company", "PostalCode"
            }
        ));
        tblSpaces.setColumnSelectionAllowed(true);
        tblSpaces.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                tblSpacesMouseClicked(evt);
            }
        });
        jScrollPane2.setViewportView(tblSpaces);

        lblSpaceId.setText("SpaceId");

        lblSpaceDesc.setText("Description");

        lblCapacity.setText("Capacity");

        lblPriceHour.setText("Price/Hour");

        lblPriceDay.setText("Price/Day");

        lblUtrlMap.setText("URL Map");

        lblHowToGet.setText("How to get");

        lblPostalCode.setText("PostalCode");

        lblCity.setText("City");

        lblSpaceDesc5.setText("Address");

        lblIncactive.setText("Intactive!");

        txtInactivUs.setBackground(new java.awt.Color(255, 51, 51));
        txtInactivUs.setForeground(new java.awt.Color(255, 255, 255));

        txtInactivDate.setBackground(new java.awt.Color(255, 51, 51));
        txtInactivDate.setForeground(new java.awt.Color(255, 255, 255));

        lblUser.setForeground(new java.awt.Color(0, 51, 255));
        lblUser.setText("USER!");

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGap(38, 38, 38)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(lblFind1, javax.swing.GroupLayout.PREFERRED_SIZE, 80, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(cbFind1, javax.swing.GroupLayout.PREFERRED_SIZE, 138, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(lblFindValue)
                        .addGap(18, 18, 18)
                        .addComponent(txtFindValue, javax.swing.GroupLayout.PREFERRED_SIZE, 187, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(48, 48, 48)
                        .addComponent(btnFind, javax.swing.GroupLayout.PREFERRED_SIZE, 104, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 57, Short.MAX_VALUE)
                        .addComponent(lblUser, javax.swing.GroupLayout.PREFERRED_SIZE, 78, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                        .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 708, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGroup(jPanel1Layout.createSequentialGroup()
                            .addComponent(lblIncactive)
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                            .addComponent(txtInactivUs, javax.swing.GroupLayout.PREFERRED_SIZE, 92, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                            .addComponent(txtInactivDate, javax.swing.GroupLayout.PREFERRED_SIZE, 89, javax.swing.GroupLayout.PREFERRED_SIZE)))))
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                .addGap(27, 27, 27)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanel1Layout.createSequentialGroup()
                        .addGap(11, 11, 11)
                        .addComponent(lblSpaceDesc5)
                        .addGap(40, 40, 40)
                        .addComponent(txtAddress, javax.swing.GroupLayout.DEFAULT_SIZE, 675, Short.MAX_VALUE))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGap(13, 13, 13)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                                .addComponent(lblCapacity)
                                .addGap(38, 38, 38))
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addComponent(lblSpaceId)
                                .addGap(38, 38, 38)))
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                            .addComponent(txtSpaceId, javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(txtCapacity, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.PREFERRED_SIZE, 51, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(70, 70, 70)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(lblSpaceDesc, javax.swing.GroupLayout.Alignment.TRAILING)
                            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(lblCity)
                                    .addComponent(lblPriceHour))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)))
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addGap(27, 27, 27)
                                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(txtCity, javax.swing.GroupLayout.DEFAULT_SIZE, 471, Short.MAX_VALUE)
                                    .addGroup(jPanel1Layout.createSequentialGroup()
                                        .addComponent(txtPriceH, javax.swing.GroupLayout.PREFERRED_SIZE, 60, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addGap(43, 43, 43)
                                        .addComponent(lblPriceDay)
                                        .addGap(38, 38, 38)
                                        .addComponent(txtPriceD, javax.swing.GroupLayout.PREFERRED_SIZE, 60, javax.swing.GroupLayout.PREFERRED_SIZE))))
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addGap(28, 28, 28)
                                .addComponent(txtDescription, javax.swing.GroupLayout.DEFAULT_SIZE, 470, Short.MAX_VALUE))))
                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(lblHowToGet)
                            .addComponent(lblPostalCode)
                            .addComponent(lblUtrlMap))
                        .addGap(40, 40, 40)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(txtZipCode, javax.swing.GroupLayout.PREFERRED_SIZE, 62, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(txtHowToGet, javax.swing.GroupLayout.DEFAULT_SIZE, 671, Short.MAX_VALUE)
                            .addComponent(txtUrlMap, javax.swing.GroupLayout.DEFAULT_SIZE, 671, Short.MAX_VALUE))))
                .addContainerGap())
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGap(16, 16, 16)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(lblFind1)
                            .addComponent(cbFind1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(lblFindValue)
                            .addComponent(txtFindValue, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(16, 16, 16))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addContainerGap()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(btnFind, javax.swing.GroupLayout.PREFERRED_SIZE, 33, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(lblUser))))
                .addGap(11, 11, 11)
                .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 143, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lblIncactive)
                    .addComponent(txtInactivDate, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(txtInactivUs, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(51, 51, 51)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(txtSpaceId, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(lblSpaceId))
                        .addGap(18, 18, 18)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(txtCapacity, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(lblCapacity)))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(txtDescription, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(lblSpaceDesc))
                        .addGap(18, 18, 18)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(txtPriceH, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(lblPriceHour)
                            .addComponent(lblPriceDay)
                            .addComponent(txtPriceD, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))))
                .addGap(18, 18, 18)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(txtUrlMap, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(lblUtrlMap))
                .addGap(18, 18, 18)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(txtHowToGet, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(lblHowToGet))
                .addGap(18, 18, 18)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(txtZipCode, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(lblPostalCode)
                    .addComponent(lblCity)
                    .addComponent(txtCity, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(txtAddress, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(lblSpaceDesc5))
                .addGap(44, 44, 44))
        );

        btnNew.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icons/add.png"))); // NOI18N
        btnNew.setText("Add");
        btnNew.setMaximumSize(new java.awt.Dimension(71, 26));
        btnNew.setMinimumSize(new java.awt.Dimension(71, 26));
        btnNew.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnNewActionPerformed(evt);
            }
        });

        btnModif.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icons/user_edit.png"))); // NOI18N
        btnModif.setText("Modif");
        btnModif.setMaximumSize(new java.awt.Dimension(71, 26));
        btnModif.setMinimumSize(new java.awt.Dimension(71, 26));
        btnModif.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnModifActionPerformed(evt);
            }
        });

        btnSave.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icons/accept.png"))); // NOI18N
        btnSave.setText("Save");
        btnSave.setMaximumSize(new java.awt.Dimension(71, 26));
        btnSave.setMinimumSize(new java.awt.Dimension(71, 26));
        btnSave.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnSaveActionPerformed(evt);
            }
        });

        btnDelete.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icons/delete.png"))); // NOI18N
        btnDelete.setText("Delete");
        btnDelete.setMaximumSize(new java.awt.Dimension(71, 26));
        btnDelete.setMinimumSize(new java.awt.Dimension(71, 26));
        btnDelete.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnDeleteActionPerformed(evt);
            }
        });

        btnCancel.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icons/cancel.png"))); // NOI18N
        btnCancel.setText("Cancel");
        btnCancel.setMaximumSize(new java.awt.Dimension(71, 26));
        btnCancel.setMinimumSize(new java.awt.Dimension(71, 26));
        btnCancel.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnCancelActionPerformed(evt);
            }
        });

        btnBack.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icons/door_out.png"))); // NOI18N
        btnBack.setText("Back");
        btnBack.setMaximumSize(new java.awt.Dimension(71, 26));
        btnBack.setMinimumSize(new java.awt.Dimension(71, 26));
        btnBack.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnBackActionPerformed(evt);
            }
        });

        jPanel2.setBackground(new java.awt.Color(255, 255, 255));

        tblSpaceResources.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null}
            },
            new String [] {
                "Title 1", "Title 2", "Title 3", "Title 4"
            }
        ));
        tblSpaceResources.setShowVerticalLines(false);
        jScrollPane1.setViewportView(tblSpaceResources);

        lblSpaceDesc6.setText("Spaces Resources");

        btnAddRes.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icons/add.png"))); // NOI18N
        btnAddRes.setText("Add");
        btnAddRes.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnAddResActionPerformed(evt);
            }
        });

        btnDelRes.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icons/delete.png"))); // NOI18N
        btnDelRes.setText("Delete");
        btnDelRes.setMaximumSize(new java.awt.Dimension(71, 25));
        btnDelRes.setMinimumSize(new java.awt.Dimension(71, 25));
        btnDelRes.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnDelResActionPerformed(evt);
            }
        });

        btnDelAllRes.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icons/delete.png"))); // NOI18N
        btnDelAllRes.setText("Delete All");
        btnDelAllRes.setMaximumSize(new java.awt.Dimension(71, 25));
        btnDelAllRes.setMinimumSize(new java.awt.Dimension(71, 25));
        btnDelAllRes.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnDelAllResActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addGap(19, 19, 19)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 304, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 58, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(btnDelRes, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 124, Short.MAX_VALUE)
                            .addComponent(btnAddRes, javax.swing.GroupLayout.DEFAULT_SIZE, 124, Short.MAX_VALUE)
                            .addComponent(btnDelAllRes, javax.swing.GroupLayout.DEFAULT_SIZE, 124, Short.MAX_VALUE)))
                    .addComponent(lblSpaceDesc6))
                .addGap(18, 18, 18)
                .addComponent(cbResources, javax.swing.GroupLayout.PREFERRED_SIZE, 235, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(44, 44, 44))
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(lblSpaceDesc6)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(cbResources, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(btnAddRes))
                        .addGap(27, 27, 27)
                        .addComponent(btnDelRes, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(btnDelAllRes, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 112, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(12, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                        .addComponent(btnSave, javax.swing.GroupLayout.PREFERRED_SIZE, 146, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(btnDelete, javax.swing.GroupLayout.PREFERRED_SIZE, 146, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                                .addComponent(btnModif, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addComponent(btnNew, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.PREFERRED_SIZE, 146, javax.swing.GroupLayout.PREFERRED_SIZE))))
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                        .addComponent(btnBack, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(btnCancel, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.PREFERRED_SIZE, 146, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(btnNew, javax.swing.GroupLayout.PREFERRED_SIZE, 31, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(btnModif, javax.swing.GroupLayout.PREFERRED_SIZE, 31, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(11, 11, 11)
                        .addComponent(btnDelete, javax.swing.GroupLayout.PREFERRED_SIZE, 31, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(btnSave, javax.swing.GroupLayout.PREFERRED_SIZE, 31, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(btnCancel, javax.swing.GroupLayout.PREFERRED_SIZE, 31, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(430, 430, 430)
                        .addComponent(btnBack, javax.swing.GroupLayout.PREFERRED_SIZE, 31, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, 510, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents


    /*
     * Carga la lista de recursos disponibles
     */
    private void cargarComboResources(JComboBox combo, List lista) {
        String item;
        String InactUser = null;
        for (Object obj : lista) {
            InactUser = ((Resource) obj).getInactivationUser();
            if (InactUser != null && InactUser != "") {
                item = ((Resource) obj).getResourceId() + " | " + ((Resource) obj).getResourceDescription().trim();
                combo.addItem(item);
            }
        }
    }

    /***************************************************************************
     *  Procediment per habilitar/dehabilitar objectes
     ****************************************************************************/
    private void ObjectsStartStatus() {
        //habilitem els objectes texts per a l'entrada de dadaes
        EnableObjects(false);
        //Netejem objectes de txt
        CleanTxt();
        NewSpace = false;
        btnNew.setEnabled(true);
        btnModif.setEnabled(false);
        btnDelete.setEnabled(false);
        btnSave.setEnabled(false);
        btnCancel.setEnabled(false);
        btnBack.setEnabled(true);
        tblSpaces.setEnabled(true);
        txtInactivDate.setVisible(false);
        txtInactivUs.setVisible(false);
        lblIncactive.setVisible(false);
        txtSpaceId.setBackground(Color.white);
        txtDescription.setBackground(Color.white);
        txtCapacity.setBackground(Color.white);
        txtPriceH.setBackground(Color.white);
        txtPriceD.setBackground(Color.white);
        txtZipCode.setBackground(Color.white);
        btnAddRes.setEnabled(false);
        btnDelRes.setEnabled(false);
        btnDelAllRes.setEnabled(false);
        jPanel2.setVisible(false);
    }

    /***************************************************************************
     *  Procediment per habilitar/dehabilitar objectes
     ****************************************************************************/
    private void EnableObjects(Boolean EnableObj) {
        txtSpaceId.setEnabled(EnableObj);
        txtDescription.setEnabled(EnableObj);
        txtCapacity.setEnabled(EnableObj);
        txtPriceH.setEnabled(EnableObj);
        txtPriceD.setEnabled(EnableObj);
        txtUrlMap.setEnabled(EnableObj);
        txtHowToGet.setEnabled(EnableObj);
        txtZipCode.setEnabled(EnableObj);
        txtCity.setEnabled(EnableObj);
        txtAddress.setEnabled(EnableObj);
        jPanel2.setVisible(true);
        //txtFindValue.setEnabled(EnableObj);

    }

    /***************************************************************************
     *   Proceciment per netejar les caselles de text
     ****************************************************************************/
    private void CleanTxt() {
        txtSpaceId.setText("");
        txtDescription.setText("");
        txtCapacity.setText("");
        txtPriceH.setText("");
        txtPriceD.setText("");
        txtUrlMap.setText("");
        txtHowToGet.setText("");
        txtZipCode.setText("");
        txtCity.setText("");
        txtAddress.setText("");
    }

    /***************************************************************************
     *  Buscar Spaces
     ****************************************************************************/
    /*
     * Carga la lista que se le env�a por par�metro en el combo del par�metro
     */
    private void cargarGrid() throws RemoteException, edu.uoc.tdp.common.EIssueException {
        //Table Usuers per busquedes
        try {
            //remoto = new ManagementSpaces();
            List<Space> SpacesList = Client.remoteMaintenance.GetAllSpacesTable();
            //set the entity objects in the list
            TableModelSpace1 model = new TableModelSpace1(SpacesList);
            tblSpaces.setModel(model);
            boolean rowSelectionAllowed = tblSpaces.getRowSelectionAllowed();
            tblSpaces.setCellSelectionEnabled(false);
        } catch (RemoteException ex) {
            Logger.getLogger(PanelUser.class.getName()).log(Level.SEVERE, null, ex);
            //lblMessage.setText("Error" + ex.toString());
        } catch (edu.uoc.tdp.common.EIssueException ex) {
            Logger.getLogger(PanelUser.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    private void ShowSpace(Integer SpaceId) throws RemoteException, edu.uoc.tdp.common.EIssueException {
        //Table Usuers per busquedes
        try {

            if (SpaceId > 0) {
                List<Space> SpacesList = null;
                SpacesList = Client.remoteMaintenance.GetOneSpace(SpaceId);
                Space SpaceActiu = SpacesList.get(0);
                txtSpaceId.setText(String.valueOf(String.valueOf(SpaceActiu.getSpaceId())));
                txtDescription.setText(SpaceActiu.getSpaceDescription().trim());
                txtCapacity.setText(String.valueOf(SpaceActiu.getCapacity()));
                txtPriceH.setText(String.valueOf(SpaceActiu.getPriceHour()));
                txtPriceD.setText(String.valueOf(SpaceActiu.getPriceDay()));
                txtUrlMap.setText(SpaceActiu.getUrl_map());
                txtHowToGet.setText(SpaceActiu.getHowToGet());
                txtZipCode.setText(String.valueOf(SpaceActiu.getPostalCode()));
                txtCity.setText(SpaceActiu.getCity());
                txtAddress.setText(SpaceActiu.getAddress());
                jPanel2.setVisible(true);

                //Eliminem espais del string. Ho fem aqui pq el Trim si no hi ha res dona error!?!?
                if (txtUrlMap.getText().length() > 0) {
                    txtUrlMap.setText(txtUrlMap.getText().trim());
                }
                if (txtHowToGet.getText().length() > 0) {
                    txtHowToGet.setText(txtHowToGet.getText().trim());
                }
                if (txtCity.getText().length() > 0) {
                    txtCity.setText(txtCity.getText().trim());
                }
                if (txtAddress.getText().length() > 0) {
                    txtAddress.setText(txtAddress.getText().trim());
                }

                String InactUser = null;
                InactUser = SpaceActiu.getInactivationUser();

                if (InactUser == null || InactUser == "") {
                    txtInactivDate.setVisible(false);
                    txtInactivUs.setVisible(false);
                    lblIncactive.setVisible(false);
                    btnModif.setEnabled(true);
                    btnDelete.setEnabled(true);
                    btnAddRes.setEnabled(true);
                    btnDelRes.setEnabled(true);
                    btnDelAllRes.setEnabled(true);
                } else {
                    DateFormat formatter;
                    formatter = new SimpleDateFormat("dd-MMM-yy");
                    txtInactivDate.setText(formatter.format(SpaceActiu.getInactivationDate()));
                    txtInactivUs.setText(SpaceActiu.getInactivationUser());
                    txtInactivDate.setVisible(true);
                    txtInactivUs.setVisible(true);
                    lblIncactive.setVisible(true);
                    btnModif.setEnabled(false);
                    btnDelete.setEnabled(false);
                    btnAddRes.setEnabled(false);
                    btnDelRes.setEnabled(false);
                    btnDelAllRes.setEnabled(false);
                }

                //Omplim Grid Spaces
                try {
                    cargarGridResources(Integer.parseInt(txtSpaceId.getText()));
                } catch (edu.uoc.tdp.common.EIssueException ex) { //FIXME
                    Logger.getLogger(PanelSpace.class.getName()).log(Level.SEVERE, null, ex);
                }


            }
        } catch (RemoteException ex) {
            Logger.getLogger(PanelUser.class.getName()).log(Level.SEVERE, null, ex);
        } catch (edu.uoc.tdp.common.EIssueException ex) {
            Logger.getLogger(PanelUser.class.getName()).log(Level.SEVERE, null, ex);
            //lblMessage.setText("Error" + ex.toString());
        }
    }

    /*
     * Carga la lista que se le env�a por par�metro en el combo del par�metro
     */
    private void cargarGridResources(Integer IdSpace) throws RemoteException, edu.uoc.tdp.common.EIssueException {
        //Table Usuers per busquedes
        try {
            //remoto = new ManagementSpaces();
            List<Resource> ResList = Client.remoteMaintenance.GetAllResourcesFromSpace(IdSpace);
            //set the entity objects in the list
            TableModelSpaceResoures model = new TableModelSpaceResoures(ResList);
            tblSpaceResources.setModel(model);
            boolean rowSelectionAllowed = tblSpaces.getRowSelectionAllowed();
            tblSpaceResources.setCellSelectionEnabled(false);
        } catch (RemoteException ex) {
            Logger.getLogger(PanelUser.class.getName()).log(Level.SEVERE, null, ex);
            //lblMessage.setText("Error" + ex.toString());
        } catch (edu.uoc.tdp.common.EIssueException ex) {
            Logger.getLogger(PanelUser.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    private void tblSpacesMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_tblSpacesMouseClicked

        int fila = tblSpaces.rowAtPoint(evt.getPoint());
        int columna = tblSpaces.columnAtPoint(evt.getPoint());
        if ((fila > -1) && (columna > -1)) {
            try {
                String Sp = String.valueOf(tblSpaces.getValueAt(fila, 0));
                ShowSpace(Integer.parseInt(Sp));
            } catch (RemoteException ex) {
                Logger.getLogger(PanelResource.class.getName()).log(Level.SEVERE, null, ex);
            } catch (edu.uoc.tdp.common.EIssueException ex) {
                Logger.getLogger(PanelResource.class.getName()).log(Level.SEVERE, null, ex);
            }
        }
    }//GEN-LAST:event_tblSpacesMouseClicked

    /***************************************************************************
     *   BTN - Buscar Spaces / Filtre
     ****************************************************************************/
    private void btnFindActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnFindActionPerformed
        //Table Usuers per busquedes
        try {

            if (txtFindValue.getText().length() == 0) {
                //Omplim Grid amb tots els 
                cargarGrid();
            } else {
                Integer indx = cbFind1.getSelectedIndex();
                //remoto = new ManagementSpaces();
                List<Space> SpacessList = null;

                switch (indx) {
                    case 0:
                        SpacessList = Client.remoteMaintenance.GetSpace_FindByDesc(txtFindValue.getText());
                        break;
                    case 1:
                        SpacessList = Client.remoteMaintenance.GetSpace_FindByPostalCode(Integer.parseInt(txtFindValue.getText()));
                        break;
                }

                TableModelSpace1 model = new TableModelSpace1(SpacessList);
                tblSpaces.setModel(model);
                tblSpaces.getRowSelectionAllowed();
            }
        } catch (RemoteException ex) {
            Logger.getLogger(PanelSpace.class.getName()).log(Level.SEVERE, null, ex);
        } catch (edu.uoc.tdp.common.EIssueException ex) {
            Logger.getLogger(PanelSpace.class.getName()).log(Level.SEVERE, null, ex);
        }
    }//GEN-LAST:event_btnFindActionPerformed

    private void btnDeleteActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnDeleteActionPerformed
        int resp = JOptionPane.showConfirmDialog(null, "Confirma eliminar?", "Eliminar", JOptionPane.YES_NO_OPTION);
        if (resp == JOptionPane.YES_OPTION) {
            InactivateSpace();
        }
    }//GEN-LAST:event_btnDeleteActionPerformed

    private void InactivateSpace() {
        try {
            //remoto = new ManagementSpaces();
            Client.remoteMaintenance.SaveInactivationSpace(Integer.parseInt(txtSpaceId.getText()), UsuarioActivo);
            ObjectsStartStatus();
        } catch (RemoteException ex) {
            Logger.getLogger(PanelResource.class.getName()).log(Level.SEVERE, null, ex);
        } catch (edu.uoc.tdp.common.EIssueException ex) {
            Logger.getLogger(PanelResource.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    private void btnBackActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnBackActionPerformed
        this.dispose();
    }//GEN-LAST:event_btnBackActionPerformed

    /***************************************************************************
     *   BTN - NOU SPACE
     ****************************************************************************/
    private void btnNewActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnNewActionPerformed
        //habilitem els objectes texts per a l'entrada de dadaes
        EnableObjects(true);
        //Netejem objectes de txt
        CleanTxt();
        NewSpace = true;
        btnNew.setEnabled(false);
        btnModif.setEnabled(false);
        btnDelete.setEnabled(false);
        btnSave.setEnabled(true);
        btnCancel.setEnabled(true);
        btnBack.setEnabled(true);
        tblSpaces.setEnabled(false);
    }//GEN-LAST:event_btnNewActionPerformed

    /***************************************************************************
     *   BTN - Modificar Spce
     ****************************************************************************/
    private void btnModifActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnModifActionPerformed
        EnableObjects(true);
        btnModif.setEnabled(false);
        btnNew.setEnabled(false);
        btnCancel.setEnabled(true);
        btnSave.setEnabled(true);
        tblSpaces.setEnabled(false);
        txtSpaceId.setEnabled(false);
    }//GEN-LAST:event_btnModifActionPerformed

    /***************************************************************************
     *   BTN - CANCELAR
     ****************************************************************************/
    private void btnCancelActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnCancelActionPerformed
        ObjectsStartStatus();
    }//GEN-LAST:event_btnCancelActionPerformed

    /***************************************************************************
     *   BTN - SAVE
     ****************************************************************************/
    private void btnSaveActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnSaveActionPerformed
        try {

            boolean DataOk = true;
            String TxtErr = null;

            if ((NewSpace) && txtSpaceId.getText().length() < 1) {
                DataOk = false;
                TxtErr = "LengthSpaceID";
                txtSpaceId.setBackground(Color.red);
            }

            try {
                if (Double.parseDouble(txtCapacity.getText()) <= 0) {
                    DataOk = false;
                    TxtErr = "Capacity";
                    txtCapacity.setBackground(Color.red);
                }
            } catch (NumberFormatException ex) {
                DataOk = false;
                txtCapacity.setBackground(Color.red);
            }


            if (txtDescription.getText().length() < 1) {
                DataOk = false;
                TxtErr = "Description";
                txtDescription.setBackground(Color.red);
            }


            try {
                if (Double.parseDouble(txtPriceD.getText()) < 0) {
                    DataOk = false;
                    TxtErr = "PriceDay < 0";
                    txtPriceD.setBackground(Color.red);
                }
            } catch (NumberFormatException ex) {
                DataOk = false;
                txtPriceD.setBackground(Color.red);
            }

            try {
                if (Double.parseDouble(txtPriceH.getText()) <= 0) {
                    DataOk = false;
                    TxtErr = "PriceHour < 0";
                    txtPriceH.setBackground(Color.red);
                }
            } catch (NumberFormatException ex) {
                DataOk = false;
                txtPriceH.setBackground(Color.red);
            }

            try {
                if (Double.parseDouble(txtZipCode.getText()) <= 0) {
                    DataOk = false;
                    TxtErr = "ZipCode";
                    txtZipCode.setBackground(Color.red);
                }
            } catch (NumberFormatException ex) {
                DataOk = false;
                txtZipCode.setBackground(Color.red);
            }


            try {
                if ((NewSpace) && Client.remoteMaintenance.CheckExistsSpace(Integer.parseInt(txtSpaceId.getText()))) {
                    DataOk = false;
                    TxtErr = "Duplicate ID";
                    txtSpaceId.setBackground(Color.red);
                    JOptionPane.showMessageDialog(this, "Error! Ya existe esta ID", "Error", JOptionPane.ERROR_MESSAGE);
                }
            } catch (RemoteException ex) {
                Logger.getLogger(PanelSpace.class.getName()).log(Level.SEVERE, null, ex);
            } catch (edu.uoc.tdp.common.EIssueException ex) {
                Logger.getLogger(PanelSpace.class.getName()).log(Level.SEVERE, null, ex);
            }

            if (DataOk) {

                Integer spaceid = Integer.parseInt(txtSpaceId.getText());
                String spacedescription = txtDescription.getText();
                Integer capacity = Integer.parseInt(txtCapacity.getText());
                Double price_hour = Double.parseDouble(txtPriceH.getText());
                Double price_day = Double.parseDouble(txtPriceD.getText());
                String url_map = txtUrlMap.getText();
                String how_to_get = txtHowToGet.getText();
                Integer postal_code = Integer.parseInt(txtZipCode.getText());
                String city = txtCity.getText();
                String space_address = txtAddress.getText();
                Date d1 = new Date();
                Date creation_date = new Date(d1.getDate());
                String creation_user = UsuarioActivo;

                EspacioTrabajo = new Space(spaceid, spacedescription, capacity, price_hour, price_day, url_map, how_to_get, postal_code, city, space_address, creation_date, creation_user, null, null, null);
                //Space(spaceid, spacedescription, capacity, price_hour, price_day, url_map, how_to_get, postal_code, city, space_address, creation_date, creation_user, inactivation_date, inactivation_user, record_date){
                boolean result = false;

                try {
                    if (NewSpace) {
                        result = Client.remoteMaintenance.SaveSpace(EspacioTrabajo);
                    } else {
                        result = Client.remoteMaintenance.SaveSpaceChanges(EspacioTrabajo);
                    }
                    if (result) {
                        ObjectsStartStatus();
                        cargarGrid();
                    } else {
                        JOptionPane.showMessageDialog(this, "Error al guardar los datos", "Error", JOptionPane.ERROR_MESSAGE);
                    }
                } catch (RemoteException ex) {
                    Logger.getLogger(PanelResource.class.getName()).log(Level.SEVERE, null, ex);
                } catch (edu.uoc.tdp.common.EIssueException ex) {
                    Logger.getLogger(PanelResource.class.getName()).log(Level.SEVERE, null, ex);
                }

            } else {
                JOptionPane.showMessageDialog(this, "Datos incorrectos!", "Error", JOptionPane.ERROR_MESSAGE);
            }

        } catch (MissingResourceException e) {
        }
    }//GEN-LAST:event_btnSaveActionPerformed

    /***************************************************************************
     *   BTN - Afegir Recurs al espai seleccionat
     ****************************************************************************/
    private void btnAddResActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnAddResActionPerformed

        Integer IdRes = -1;
        String item = cbResources.getItemAt(cbResources.getSelectedIndex()).toString();
        int inicio = item.indexOf("|");
        IdRes = Integer.parseInt(item.substring(0, inicio - 1));

        if (CheckResourceExist(IdRes) == false) {
            try {
                boolean result = Client.remoteMaintenance.SaveSpaceResource(Integer.parseInt(txtSpaceId.getText()), IdRes);
                if (result) {
                    //Omplim Grid Space-Resources
                    try {
                        cargarGridResources(Integer.parseInt(txtSpaceId.getText()));
                    } catch (edu.uoc.tdp.common.EIssueException ex) {
                        Logger.getLogger(PanelSpace.class.getName()).log(Level.SEVERE, null, ex);
                    }
                }
            } catch (RemoteException ex) {
                Logger.getLogger(PanelSpace.class.getName()).log(Level.SEVERE, null, ex);
            } catch (edu.uoc.tdp.common.EIssueException ex) {
                Logger.getLogger(PanelSpace.class.getName()).log(Level.SEVERE, null, ex);
            }
        } else {
            JOptionPane.showMessageDialog(this, "Este recurso ya esta asociado al Espacio!", "Error", JOptionPane.ERROR_MESSAGE);
        }
    }//GEN-LAST:event_btnAddResActionPerformed

    /***************************************************************************
     *   BTN - Eliminar Recurs al seleccionat del grid
     ****************************************************************************/
    private void btnDelResActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnDelResActionPerformed

        int resp = JOptionPane.showConfirmDialog(null, "Confirma eliminar el recurso del aula?", "Eliminar", JOptionPane.YES_NO_OPTION);
        if (resp == JOptionPane.YES_OPTION) {
            try {

                //int rowIndex = tblSpaceResources.getSelectedRow();
                String IdRes = String.valueOf(tblSpaceResources.getValueAt(tblSpaceResources.getSelectedRow(), 0));

                InactivateSpaceRessource(Integer.parseInt(IdRes));

                //Omplim Grid Space-Resources
                try {
                    cargarGridResources(Integer.parseInt(txtSpaceId.getText()));
                } catch (edu.uoc.tdp.common.EIssueException ex) {
                    Logger.getLogger(PanelSpace.class.getName()).log(Level.SEVERE, null, ex);
                }

            } catch (RemoteException ex) {
                Logger.getLogger(PanelSpace.class.getName()).log(Level.SEVERE, null, ex);
            } catch (edu.uoc.tdp.common.EIssueException ex) {
                Logger.getLogger(PanelSpace.class.getName()).log(Level.SEVERE, null, ex);
            }
        }
    }//GEN-LAST:event_btnDelResActionPerformed

    private void btnDelAllResActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnDelAllResActionPerformed

        try {
            int resp = JOptionPane.showConfirmDialog(null, "Confirma eliminar todos los recursos del aula?", "Eliminar", JOptionPane.YES_NO_OPTION);
            if (resp == JOptionPane.YES_OPTION) {
                for (int i = 0; i < tblSpaceResources.getRowCount(); i++) {
                    String IdRes = String.valueOf(tblSpaceResources.getValueAt(i, 0));
                    InactivateSpaceRessource(Integer.parseInt(IdRes));
                }
                //Omplim Grid Space-Resources
                try {
                    cargarGridResources(Integer.parseInt(txtSpaceId.getText()));
                } catch (edu.uoc.tdp.common.EIssueException ex) {
                    Logger.getLogger(PanelSpace.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
        } catch (RemoteException ex) {
            Logger.getLogger(PanelSpace.class.getName()).log(Level.SEVERE, null, ex);
        } catch (edu.uoc.tdp.common.EIssueException ex) {
            Logger.getLogger(PanelSpace.class.getName()).log(Level.SEVERE, null, ex);
        }
    }//GEN-LAST:event_btnDelAllResActionPerformed

    private void InactivateSpaceRessource(int IdRes) throws RemoteException, edu.uoc.tdp.common.EIssueException {

        Client.remoteMaintenance.DeleteSpaceResource(Integer.parseInt(txtSpaceId.getText()), IdRes);

    }

    public boolean CheckResourceExist(Integer IdRes) {
        boolean Result = false;
        for (int i = 0; i < tblSpaceResources.getRowCount(); i++) {
            if (tblSpaceResources.getValueAt(i, 0) == IdRes) {
                Result = true;
            }
        }
        return Result;
    }

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(PanelSpace.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(PanelSpace.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(PanelSpace.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(PanelSpace.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                try {
                    new PanelSpace().setVisible(true);
                } catch (RemoteException ex) {
                    Logger.getLogger(PanelSpace.class.getName()).log(Level.SEVERE, null, ex);
                } catch (edu.uoc.tdp.common.EIssueException ex) {
                    Logger.getLogger(PanelSpace.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnAddRes;
    private javax.swing.JButton btnBack;
    private javax.swing.JButton btnCancel;
    private javax.swing.JButton btnDelAllRes;
    private javax.swing.JButton btnDelRes;
    private javax.swing.JButton btnDelete;
    private javax.swing.JButton btnFind;
    private javax.swing.JButton btnModif;
    private javax.swing.JButton btnNew;
    private javax.swing.JButton btnSave;
    private javax.swing.JComboBox cbFind1;
    private javax.swing.JComboBox cbResources;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JLabel lblCapacity;
    private javax.swing.JLabel lblCity;
    private javax.swing.JLabel lblFind1;
    private javax.swing.JLabel lblFindValue;
    private javax.swing.JLabel lblHowToGet;
    private javax.swing.JLabel lblIncactive;
    private javax.swing.JLabel lblPostalCode;
    private javax.swing.JLabel lblPriceDay;
    private javax.swing.JLabel lblPriceHour;
    private javax.swing.JLabel lblSpaceDesc;
    private javax.swing.JLabel lblSpaceDesc5;
    private javax.swing.JLabel lblSpaceDesc6;
    private javax.swing.JLabel lblSpaceId;
    private javax.swing.JLabel lblUser;
    private javax.swing.JLabel lblUtrlMap;
    private javax.swing.JTable tblSpaceResources;
    private javax.swing.JTable tblSpaces;
    private javax.swing.JTextField txtAddress;
    private javax.swing.JTextField txtCapacity;
    private javax.swing.JTextField txtCity;
    private javax.swing.JTextField txtDescription;
    private javax.swing.JTextField txtFindValue;
    private javax.swing.JTextField txtHowToGet;
    private javax.swing.JTextField txtInactivDate;
    private javax.swing.JTextField txtInactivUs;
    private javax.swing.JTextField txtPriceD;
    private javax.swing.JTextField txtPriceH;
    private javax.swing.JTextField txtSpaceId;
    private javax.swing.JTextField txtUrlMap;
    private javax.swing.JTextField txtZipCode;
    // End of variables declaration//GEN-END:variables

    class TableModelSpaceResource extends AbstractTableModel {

        List ResourcesList;
        String c1 = TDPLanguageUtils.getMessage(TDPLanguageConstants.CLIENT_PANELRESOURCE_TABLEC1);
        String c2 = TDPLanguageUtils.getMessage(TDPLanguageConstants.CLIENT_PANELRESOURCE_TABLEC2);
        String c3 = TDPLanguageUtils.getMessage(TDPLanguageConstants.CLIENT_PANELRESOURCE_TABLEC3);
        String c4 = TDPLanguageUtils.getMessage(TDPLanguageConstants.CLIENT_PANELRESOURCE_TABLEC4);
        String c5 = TDPLanguageUtils.getMessage(TDPLanguageConstants.CLIENT_PANELRESOURCE_TABLEC5);
//    String headerList[] = new String[]{c1, c2, c3, c4, c5};
        String headerList[] = new String[]{"ID", "Description", "Amount", "price/Hour", "price/Day"};

        public TableModelSpaceResource(List list) {
            ResourcesList = list;
        }

        @Override
        public int getColumnCount() {
            return 5;
        }

        @Override
        public int getRowCount() {
            return ResourcesList.size();
        }
        // this method is called to set the value of each cell

        @Override
        public Object getValueAt(int row, int col) {
            Object returnValue = false;
            //User entity = null;
            Resource entity = (Resource) ResourcesList.get(row);
            switch (col) {
                case 0:
                    returnValue = entity.getResourceId();
                    break;
                case 1:
                    returnValue = entity.getResourceDescription();
                    break;
                case 2:
                    returnValue = entity.getAmount();
                    break;
                case 3:
                    returnValue = entity.getPriceHour();
                    break;
                case 4:
                    returnValue = entity.getPriceDay();
                    break;
            }
            return returnValue;
        }
        //display the name of columns

        @Override
        public String getColumnName(int col) {
            return headerList[col];
        }
    }

    class TableModelSpace1 extends AbstractTableModel {

        List SpacesList;
        //String headerList[] = new String[]{"spaceid", "spacedescription", "capacity", "price_hour", "price_day", "postal_code"};
        String headerList[] = new String[]{"ID", "Description", "Capacity", "Price/hour", "Price/day", "Postal Code"};

        public TableModelSpace1(List list) {
            SpacesList = list;
        }

        @Override
        public int getColumnCount() {
            return 6;
        }

        @Override
        public int getRowCount() {
            return SpacesList.size();
        }
        // this method is called to set the value of each cell

        @Override
        public Object getValueAt(int row, int col) {
            Object returnValue = false;
            //User entity = null;
            Space entity = (Space) SpacesList.get(row);
            switch (col) {
                case 0:
                    returnValue = entity.getSpaceId();
                    break;
                case 1:
                    returnValue = entity.getSpaceDescription();
                    break;
                case 2:
                    returnValue = entity.getCapacity();
                    break;
                case 3:
                    returnValue = entity.getPriceDay();
                    break;
                case 4:
                    returnValue = entity.getPriceHour();
                    break;
                case 5:
                    returnValue = entity.getPostalCode();
                    break;
            }
            return returnValue;
        }
        //display the name of columns

        @Override
        public String getColumnName(int col) {
            return headerList[col];
        }

        
    }
    class TableModelSpaceResoures extends AbstractTableModel {

            List SpacesList;
            String headerList[] = new String[]{"ID", "Description",};

            public TableModelSpaceResoures(List list) {
                SpacesList = list;
            }

            @Override
            public int getColumnCount() {
                return 2;
            }

            @Override
            public int getRowCount() {
                return SpacesList.size();
            }
            // this method is called to set the value of each cell

            @Override
            public Object getValueAt(int row, int col) {
                Object returnValue = false;
                //User entity = null;
                Resource entity = (Resource) SpacesList.get(row);
                switch (col) {
                    case 0:
                        returnValue = entity.getResourceId();
                        break;
                    case 1:
                        returnValue = entity.getResourceDescription();
                        break;
                }
                return returnValue;
            }
            //display the name of columns

            @Override
            public String getColumnName(int col) {
                return headerList[col];
            }
        }
}
